﻿using System;
using System.Collections.ObjectModel;

namespace Neovolve.Extensibility.ReSharper
{
    /// <summary>
    /// The <see cref="AliasTypeMappingCollection"/>
    /// class is used to store a set of <see cref="AliasTypeMapping"/> objects.
    /// </summary>
    internal class AliasTypeMappingCollection : Collection<AliasTypeMapping>
    {
        /// <summary>
        /// Finds the name of the by type.
        /// </summary>
        /// <param name="typeName">
        /// Name of the type.
        /// </param>
        /// <returns>
        /// A <see cref="AliasTypeMapping"/> instance.
        /// </returns>
        public AliasTypeMapping FindByTypeName(String typeName)
        {
            // Loop through each mapping
            for (Int32 index = 0; index < Count; index++)
            {
                AliasTypeMapping mapping = this[index];

                // Check if the mapping was found
                if (mapping.AliasTypeName == typeName
                    || mapping.ClrTypeName == typeName)
                {
                    return mapping;
                }
            }

            // We didn't find the mapping
            return null;
        }
    }
}